import React, { Component } from "react"
import { Modal, Form, Switch, Select, InputNumber } from 'antd'
import constant from "../constant"
import { messages } from "share/common"

const { Option } = Select;

@Form.create()
class RecheckModal extends Component{

  componentWillReceiveProps(nextProps) {
    if (!nextProps.visible || nextProps.visible === this.props.visible) {
      return -1;
    }
    this.props.form.resetFields();
  }

  onOk = () => {
    this.props.form.validateFieldsAndScroll((err, value) => {
      if (!err) {
        const { record, onOk } = this.props;
        onOk(Object.assign(record, value));
      }
    })
  };

  render() {
    const { cancel, visible, record } = this.props;
    const { getFieldDecorator } = this.props.form;
    const { formItemLayout } = constant;
    return (
      <Modal
        visible={visible}
        onCancel={cancel}
        onOk={this.onOk}
        title={messages('finance-1.key423')/*复核启用条件*/}
      >
        <Form className='new-form'>
          <Form.Item
            label={messages('common.column.status')/*状态*/}
            {...formItemLayout}
          >
            {getFieldDecorator("isEnabled", {
              rules: [{ required: true }],
              valuePropName: "checked",
              initialValue: record.hasOwnProperty('isEnabled') ? record.isEnabled : true
            })(
              <Switch>{messages('finance-1.key244')/*启用temp*/}</Switch>
            )}
          </Form.Item>
          <Form.Item
            label={messages('finance-1.key425')/*收款账户类型*/}
            {...formItemLayout}
          >
            {getFieldDecorator("accountMark", {
              initialValue: record.accountMark
            })(
              <Select placeholder={messages('common.select')/*请选择*/}>
                <Option key='01'>{messages('finance-1.key426')/*对私支付*/}</Option>
                <Option key='02'>{messages('finance-1.key427')/*对公支付*/}</Option>
              </Select>
            )}
          </Form.Item>
          <Form.Item
            label={messages('finance-1.key428')/*单笔金额超*/}
            {...formItemLayout}
          >
            {getFieldDecorator("singleAmountMax", {
              initialValue: record.singleAmountMax
            })(
              <InputNumber placeholder={messages('common.please.input')/*请输入*/}/>
            )}
          </Form.Item>
          <Form.Item
            label={messages('finance-1.key429')/*批次总金额超*/}
            {...formItemLayout}
          >
            {getFieldDecorator("totalAmountMax", {
              initialValue: record.totalAmountMax
            })(
              <InputNumber placeholder={messages('common.please.input')/*请输入*/}/>
            )}
          </Form.Item>
        </Form>
      </Modal>
    )
  }

}

export default RecheckModal
